package com.dkm.ec.product.repository.impl;

import com.dkm.base.api.model.Page;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.product.domain.ProductEntity;
import com.dkm.ec.product.persistence.dao.ProductEntityQueryDao;
import com.dkm.ec.product.persistence.entity.ProductEntityPo;
import com.dkm.ec.product.repository.ProductEntityRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 对象功能:产品（抽象） Repository接口的实现类
 * 开发公司:SKG.COM
 * 开发人员:颜超敏
 * 创建时间:2014-12-17 11:30:15
 */
@Repository
public class ProductEntityRepositoryImpl extends AbstractRepository<String, ProductEntityPo,ProductEntity> implements ProductEntityRepository{
	  
	@Resource
	private  ProductEntityQueryDao productEntityQueryDao;

	public ProductEntity newInstance() {
		ProductEntityPo po = new ProductEntityPo();
		ProductEntity productEntity = SpringHelper.getBean(ProductEntity.class);
		productEntity.setData(po);
		return productEntity;
	}

	public ProductEntity newInstance(ProductEntityPo po) {
		ProductEntity productEntity = SpringHelper.getBean(ProductEntity.class);
		productEntity.setData(po);
		return productEntity;
	} 
	
	@Override
	protected IQueryDao<String, ProductEntityPo> getQueryDao() {
		return productEntityQueryDao;
	}
	
	public ProductEntityPo findByBusinessKey(String businessKey) {
		ProductEntityPo po = productEntityQueryDao.findByBusinessKey(businessKey);
		 
		return po;
	}

	@Override
	public List<ProductEntityPo> findForSelectorPaged(Map<String, Object> map,
			Page page) {
		List<ProductEntityPo> productEntityPos = productEntityQueryDao.findByKey("findForSelect", map,page);
		return productEntityPos;
	}

	@Override
	public Integer countForSelector(Map<String, Object> params) {
		return productEntityQueryDao.countByKey("countForSelect", params);
	}

	@Override
	public List<ProductEntityPo> findProdRec(String userId, String productId,
			Integer count) {
		return productEntityQueryDao.findProdRec(userId, productId, count);
	}

	@Override
	public List<ProductEntityPo> findByShopId(String shopId) {
		return productEntityQueryDao.findByShopId(shopId);
	}


}
